package com.fr.report.core;

import java.io.Serializable;

public class DynamicCellViewList
  implements Cloneable, Serializable
{
  private int[] intArray;
  private int defaultValue;

  public DynamicCellViewList(int paramInt)
  {
    this(paramInt, 10);
  }

  public DynamicCellViewList(int paramInt, int[] paramArrayOfInt)
  {
    this.defaultValue = 1;
    this.defaultValue = paramInt;
    this.intArray = paramArrayOfInt;
  }

  public DynamicCellViewList(int paramInt1, int paramInt2)
  {
    this.defaultValue = 1;
    if (paramInt2 < 0)
      throw new IllegalArgumentException("Illegal Capacity: " + paramInt2);
    this.defaultValue = paramInt1;
    this.intArray = createIntArray(paramInt2);
  }

  public void trimToSize()
  {
    for (int i = this.intArray.length - 1; i >= 0; --i)
      if (this.intArray[i] != this.defaultValue)
        break;
    if (i < this.intArray.length - 1)
    {
      int[] arrayOfInt = this.intArray;
      this.intArray = createIntArray(i + 1);
      System.arraycopy(arrayOfInt, 0, this.intArray, 0, this.intArray.length);
    }
  }

  public double getDefaultValue()
  {
    return this.defaultValue;
  }

  public void setDefaultValue(int paramInt)
  {
    this.defaultValue = paramInt;
  }

  public int getLastIndex()
  {
    trimToSize();
    return (this.intArray.length - 1);
  }

  public int get(int paramInt)
  {
    if ((paramInt < 0) || (paramInt > this.intArray.length - 1))
      return this.defaultValue;
    return this.intArray[paramInt];
  }

  public void set(int paramInt1, int paramInt2)
  {
    if (paramInt1 < 0)
      return;
    checkIntArrayBounds(paramInt1);
    this.intArray[paramInt1] = paramInt2;
  }

  public void insert(int paramInt)
  {
    insert(paramInt, 1);
  }

  public void insert(int paramInt1, int paramInt2)
  {
    if ((paramInt1 < 0) || (paramInt2 <= 0))
      return;
    checkIntArrayBounds(paramInt1);
    int[] arrayOfInt = this.intArray;
    this.intArray = new int[arrayOfInt.length + paramInt2];
    for (int i = paramInt1; i < paramInt1 + paramInt2; ++i)
      this.intArray[i] = this.defaultValue;
    System.arraycopy(arrayOfInt, 0, this.intArray, 0, paramInt1);
    System.arraycopy(arrayOfInt, paramInt1, this.intArray, paramInt1 + paramInt2, arrayOfInt.length - paramInt1);
  }

  public void remove(int paramInt)
  {
    if ((paramInt < 0) || (paramInt > this.intArray.length - 1))
      return;
    int[] arrayOfInt = this.intArray;
    this.intArray = new int[this.intArray.length - 1];
    System.arraycopy(arrayOfInt, 0, this.intArray, 0, paramInt);
    System.arraycopy(arrayOfInt, paramInt + 1, this.intArray, paramInt, arrayOfInt.length - paramInt + 1);
  }

  public void removeRange(int paramInt1, int paramInt2)
  {
    if ((paramInt1 < 0) || (paramInt2 < 0) || (paramInt1 >= this.intArray.length) || (paramInt2 >= this.intArray.length) || (paramInt1 >= paramInt2))
      return;
    int[] arrayOfInt = this.intArray;
    this.intArray = new int[arrayOfInt.length - paramInt2 - paramInt1 + 1];
    System.arraycopy(arrayOfInt, 0, this.intArray, 0, paramInt1);
    System.arraycopy(arrayOfInt, paramInt2 + 1, this.intArray, paramInt1, arrayOfInt.length - paramInt2 + 1);
  }

  public void reset()
  {
    for (int i = 0; i < this.intArray.length; ++i)
      this.intArray[i] = this.defaultValue;
  }

  public double getRangeValueFromZero(int paramInt)
  {
    return getRangeValue(0, paramInt);
  }

  public double getRangeValue(int paramInt1, int paramInt2)
  {
    double d = 0.0D;
    int i = Math.min(paramInt1, paramInt2);
    int j = Math.max(paramInt1, paramInt2);
    for (int k = i; k < j; ++k)
      d += get(k);
    return ((paramInt1 <= paramInt2) ? d : -d);
  }

  public int getValueIndex(double paramDouble)
  {
    return getValueIndex(paramDouble, 0);
  }

  public int getValueIndex(double paramDouble, int paramInt)
  {
    double d = 0.0D;
    int i = paramInt;
    while (true)
    {
      d += get(i);
      if (d > paramDouble)
        return i;
      ++i;
    }
  }

  private void checkIntArrayBounds(int paramInt)
  {
    while (paramInt >= this.intArray.length)
      doubleIntArray();
  }

  private int[] createIntArray(int paramInt)
  {
    int[] arrayOfInt = new int[paramInt];
    for (int i = 0; i < arrayOfInt.length; ++i)
      arrayOfInt[i] = this.defaultValue;
    return arrayOfInt;
  }

  private void doubleIntArray()
  {
    int[] arrayOfInt = this.intArray;
    this.intArray = new int[Math.max(10, arrayOfInt.length * 2)];
    System.arraycopy(arrayOfInt, 0, this.intArray, 0, arrayOfInt.length);
    for (int i = arrayOfInt.length; i < this.intArray.length; ++i)
      this.intArray[i] = this.defaultValue;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    trimToSize();
    DynamicCellViewList localDynamicCellViewList = (DynamicCellViewList)super.clone();
    int[] arrayOfInt = new int[this.intArray.length];
    System.arraycopy(this.intArray, 0, arrayOfInt, 0, arrayOfInt.length);
    localDynamicCellViewList.intArray = arrayOfInt;
    return localDynamicCellViewList;
  }
}